package com.jzo2o.health.job;


import com.jzo2o.common.utils.CollUtils;
import com.jzo2o.health.model.domain.OrdersRefund;
import com.jzo2o.health.properties.OrdersJobProperties;
import com.jzo2o.health.service.IOrderRefundService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单退款任务
 * @author JIAN
 */
@Slf4j
@Component
@SuppressWarnings("unused")
public class OrderRefundJob {
    @Resource
    private IOrderRefundService orderRefundService;
    @Resource
    private OrdersJobProperties ordersJobProperties;

    /**
     * 订单退款异步任务
     */
    @XxlJob(value = "handleRefundOrders")
    public void handleRefundOrders() {
        List<OrdersRefund> latestRefundInfo = orderRefundService.getLatestRefundInfo(ordersJobProperties.getRefundOrderCount());
        if (CollUtils.isEmpty(latestRefundInfo)) {
            log.info("没有需要退款的订单");
        }

        latestRefundInfo.forEach(refundInfo -> orderRefundService.refundOrder(refundInfo));
    }
}